package com.taotao.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.taotao.common.pojo.EUDataGridResult;
import com.taotao.common.pojo.EUTreeNode;
import com.taotao.mapper.ItemCatMapper;
import com.taotao.mapper.ItemMapper;
import com.taotao.pojo.Item;
import com.taotao.pojo.ItemCat;
import com.taotao.service.ItemCatService;
import com.taotao.service.ItemService;

@Service
public class ItemCatServiceImpl implements ItemCatService{
	private static Logger logger = LoggerFactory.getLogger(ItemCatServiceImpl.class);
	
	@Autowired
	private ItemCatMapper itemCatMapper;

	@Override
	public int deleteByPrimaryKey(Long id) {
		return itemCatMapper.deleteByPrimaryKey(id);
	}

	@Override
	public int insert(ItemCat record) {
		return itemCatMapper.insert(record);
	}

	@Override
	public int insertSelective(ItemCat record) {
		return itemCatMapper.insertSelective(record);
	}

	@Override
	public ItemCat selectByPrimaryKey(Long id) {
		return itemCatMapper.selectByPrimaryKey(id);
	}

	@Override
	public int updateByPrimaryKeySelective(ItemCat record) {
		return itemCatMapper.updateByPrimaryKeySelective(record);
	}

	@Override
	public int updateByPrimaryKey(ItemCat record) {
		return itemCatMapper.updateByPrimaryKey(record);
	}

	@Override
	public List<EUTreeNode> getCatList(Long parentId) {
		Map<String,Object> params = new HashMap<String,Object>();
		List<ItemCat> list = itemCatMapper.getCatList(params);
		List<EUTreeNode> resultList = new ArrayList<EUTreeNode>();
		//把列表转换成treeNodelist
		for (ItemCat tbItemCat : list) {
			EUTreeNode node = new EUTreeNode();
			node.setId(tbItemCat.getId());
			node.setText(tbItemCat.getName());
			node.setState(tbItemCat.getIsParent()?"closed":"open");
			resultList.add(node);
		}
		//返回结果
		return resultList;
	}

}
